/*
 * @(#)LocalCollectionPanel.java
 * 
 * Copyright(C) 2004 Yujin Kim
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.netexplode.jtunes.client.ui.component;

import java.awt.Color;
import java.util.List;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;

import com.netexplode.jtunes.model.media.CollectionManager;
import com.netexplode.jtunes.model.media.MediaCollection;
import com.netexplode.jtunes.model.media.MediaFile;

/**
 * <code>LocalCollectionPanel</code> represents .....
 * 
 * @author ykim
 * @version $Revision: 1.2 $
 * @since 0.1
 */
public class LocalCollectionPanel extends CollectionPanel {

    final protected void initialize() {

        tables = new JTable[CollectionManager
                .getInstance()
                .getLocalCollections()
                .size()];

        for (int i = 0; i < tables.length; i++) {
            final MediaCollection collection = (MediaCollection) CollectionManager
                    .getInstance()
                    .getLocalCollections()
                    .get(i);
            final int size = collection.size();
            final List list = collection.getMediaFiles();

            final Object[][] data = new Object[size][columnNames.length];
            for (int j = 0; j < list.size(); j++) {
                final MediaFile mf = (MediaFile) list.get(j);
                data[j][0] = mf.getTag().getArtist();
                data[j][1] = mf.getTag().getAlbum();
                data[j][2] = mf.getTag().getTitle();
                collectionLoaded = true;
            }

            tables[i] = new JTable(new DefaultTableModel(data, columnNames) {
                public boolean isCellEditable(int row, int column) {
                    return false;
                }
            });

            tables[i].setShowGrid(true);
            tables[i].setGridColor(Color.BLACK);
            tables[i].setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

            this.addEventLister(tables[i]);
            super.add(getTable());
        }
    }

    protected JTable getTable() {
        return this.tables[CollectionManager.getInstance().getLocalPosition()];
    }
}